<template>
	<view>
		<cu-custom bgColor="bg-blue"  :isBack="true"><block slot="content">报告编制</block></cu-custom>
		<view class="bg-white nav text-center">
			<view class="cu-item" :class="index==20?'text-blue cur':''"  @tap="tabSelect" :data-id="20">
				待生成
			</view>
			<view class="cu-item" :class="index==30?'text-blue cur':''"  @tap="tabSelect" :data-id="30">
				已生成
			</view>
		</view>
		<view v-for="(item,index) in orderList" :key="index" scroll-x class="bg-white margin">
			<view class="grid col-2">
				<view class="padding-left-lg margin-top-xs">
					<text class="text-black">客户姓名：</text>
					<text class="text-grey">{{item.order.submitName}}</text>
				</view>
				<view class="padding-left-lg margin-top-xs">
					<text class="text-black">手机号：</text>
					<text class="text-grey">{{item.order.submitPhone}}</text>
				</view>
			</view>
			<view class="grid col-2">
				<view class="padding-left-lg margin-top-xs">
					<text class="text-black">编码：</text>
					<text class="text-grey">{{item.orderNumber}}</text>
				</view>
				<view class="padding-left-lg margin-tb-xs">
					<text class="text-black">接受人：</text>
					<text class="text-grey">{{item.order.acceptUserName}}</text>
				</view>
			</view>
			<view class="grid col-1">
				<view class="padding-left-lg margin-top-xs">
					<text class="text-black">原始编码：</text>
					<text class="text-grey">{{item.originalCode?item.originalCode:""}}</text>
				</view>
			</view>
			<view class="grid col-1">
				<view class="padding-left-lg margin-top-xs">
					<text class="text-black">更新日期：</text>
					<text class="text-grey">{{item.updateTime}}</text>
				</view>
			</view>
			<view class="grid col-2">
				<view class="padding-left-lg margin-tb-xs">
					<text class="text-black">状态：</text>
					<text v-if="item.state==20" class="text-red">待生成</text>
					<text v-if="item.state==30" class="text-green">已生成</text>
				</view>
				<view class="padding-left-lg padding-right-lg margin-tb-xs flex justify-end">
					<button v-if="item.state=='20'" @click="goOrderDetail(item)" type="primary" class="cu-btn bg-blue sm">去生成</button>
					<button v-if="item.state=='30'" @click="goOrderDetail(item)" type="primary" class="cu-btn bg-blue sm">看报告</button>
				</view>
			</view>
		</view>
		<uni-load-more :status="moreFlag">
		</uni-load-more>
	</view>
</template>

<script>
	import uniLoadMore from "@/uniui/uni-load-more.vue"
	import { listOrderDetail,updateOrderDetail} from '@/api/modules/orderDetail.js'
	export default {
		name: "orderList",
	    components: {uniLoadMore},
		data() {
			return {
				index:20, //待复核
				orderList:[],
				pageNum:1,
				pageSize:10,
				moreFlag:"more",
				member:uni.getStorageSync('member'),
			}
		},
		onShow() {
			this.refresh()
		},
		methods: {
			tabSelect(e){
				this.index = e.currentTarget.dataset.id;
				this.refresh()
			},
			getOrderDetailList(){
				if(this.moreFlag=="noMore"){
					this.moreFlag
					return
				}
				this.moreFlag="loading"
				let member={};
				try{
					member=uni.getStorageSync('member')
				}catch(e){
					//TODO handle the exception
				}
				let data={
					pageNum:this.pageNum,
					pageSize:this.pageSize,
					state:this.index
					// ,reviewUserId:this.member.userId
				}
				listOrderDetail(data).then(res=>{
					if(res.data.code==200){
						this.orderList=this.orderList.concat(res.data.rows)
						if(res.data.total==this.orderList.length){
							this.moreFlag="noMore"
						}else{
							this.pageNum++
							this.moreFlag="more"
						}
					}else{
						uni.showToast({
							title:res.data.msg,
							duration:2000,
							success() {
							}
						})
					}
					
				})
			},
			refresh(){
				this.orderList=[]
				this.pageNum=1
				this.moreFlag="more"
				this.getOrderDetailList()
			},
			goOrderDetail(item){//?orderDetailId="+item.orderDetailId
				uni.navigateTo({
					url:"../acceptOrderDetailReport/acceptOrderDetailReport?orderDetailId="+item.orderDetailId
				})
			}
		},
		onReachBottom() {
			this.getOrderDetailList()
		},
		onPullDownRefresh() {
			this.refresh()
		}
	}
</script>

<style>
page{
	background-color: #f0f0f0;
}
</style>
